package org.microsleep;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PersistentClass implements Type {
	private Class<?> mappedClass;
	private String tableName;
	private final List<Property> columns = new ArrayList<Property>();
	private Property identifier;

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getTableName() {
		return tableName;
	}

	public void setColumns(List<Property> columns) {
		this.columns.clear();
		this.columns.addAll(columns);
	}

	public List<Property> getProperties() {
		return Collections.unmodifiableList(columns);
	}

	public void setIdentifier(Property identifier) {
		this.identifier = identifier;
	}

	public Property getIdentifier() {
		return identifier;
	}

	public void validate() {
		Util.notNull(identifier, "Class declares no Identifier!");

	}

	public void setMappedClass(Class<?> mappedClass) {
		this.mappedClass = mappedClass;
	}

	public Class<?> getMappedClass() {
		return mappedClass;
	}

	@Override
	public int hashCode() {
		return getMappedClass().hashCode();
	}
}
